//
//  2023华为OD面试手撕真题【找最大连续子串】 .swift
//  手撕代码
//
//  Created by xiaoZuDeMeng on 2024/1/30.
//

import Foundation

func 最长连续子串() {
    while let line = readLine() {
        var ss = line.components(separatedBy: ",")
        var index = 0
        var max = 0
        var left = 0, right = 0

        for i in 0..<ss.count {
            if isSubSequence(ss, index, i) {
                if max < i - index {
                    max = i - index
                    left = index
                    right = i
                }
            } else {
                index = i
            }
        }

        for i in left...right {
            print(ss[i], terminator: " ")
        }
    }
}

func isSubSequence(_ ss: [String], _ left: Int, _ right: Int) -> Bool {
    for i in left..<right {
        if !isNextValue(ss[i], ss[i + 1]) {
            return false
        }
    }
    return true
}

func isNextValue(_ s1: String, _ s2: String) -> Bool {
//    if s1 == "10" {
//        return s2 == "A"
//    }
//    if s1 == "9" {
//        return s2 == "10"
//    }
//    if let s1Char = s1.first, let s2Char = s2.first {
//        if (UnicodeScalar(s1Char.value)! + 1) == UnicodeScalar(s2Char.value)! {
//            return true
//        }
//    }
    return false
}
